package com.xiuxia.bopicturebackend.schedule;

import cn.hutool.core.collection.CollUtil;
import com.xiuxia.bopicturebackend.model.entity.Picture;
import com.xiuxia.bopicturebackend.service.PictureService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class clearCosPictureSchedule {
    @Resource
    private PictureService pictureService;

    @Scheduled(cron = "0 59 23 ? * SUN")
    public void clearCosPicture() {
        List<Picture> pictures = pictureService.getDeletedPictureList();
        if (CollUtil.isNotEmpty(pictures)) {
            for (Picture picture : pictures) {
                pictureService.clearPictureFile(picture);
            }
        }
    }
}
